package com.vcms.view.simulation.uicomponent.display;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */
import java.awt.Panel;

import com.vcms.controller.maintenance.MaintenanceController;
import com.vcms.controller.storemanagement.StoreController;
import com.vcms.entity.store.item.StoreItem;
import com.vcms.exception.VMCSException;
import com.vcms.view.simulation.uicomponent.button.ButtonItemDisplay;
import com.vcms.view.simulation.uicomponent.listener.CoinDisplayListener;

@SuppressWarnings("serial")
public class CoinDisplay extends Panel {

	public final static String TITLE = "Quantity of Coins Available";

	private StoreController storeCtrl;
	private MaintenanceController mCtrl;
	private ButtonItemDisplay bi;
	private int len;
	private int curIdx;

	public CoinDisplay(MaintenanceController mctrl) {
		mCtrl = mctrl;
		storeCtrl = mCtrl.getMainController().getStoreController();

		len = storeCtrl.getStoreSize(StoreController.CASH);
		StoreItem[] items = storeCtrl.getStoreItems(StoreController.CASH);

		bi = new ButtonItemDisplay(TITLE, items, len);

		bi.addListener(new CoinDisplayListener(mCtrl));

		bi.clear();

		this.add(bi);

	}

	public void setActive(boolean st) {
		bi.setActive(st);
	}

	/**
	 * Display the quantity of selected coin, clear other display.
	 */
	public void displayQty(int idx, int qty) throws VMCSException {
		curIdx = idx;
		bi.clear();
		bi.displayQty(idx, qty);
	}

	/**
	 * get the current displayed coin index. This is used for updating when
	 * store MachinerySimulatorPanel is changed. Not required.
	 */
	public int getCurIdx() {
		return curIdx;
	}
}